package com.jinxin.platform.cdcardpassmgr.rpc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jinxin.platform.base.common.annotation.RecEvent;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.base.common.support.PlatFormEventListener;
import com.jinxin.platform.cdcardpassmgr.common.Constant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2021-02-05
 * @Author: Lingnan
 **/
@Component
@RecEvent(eventType = "reportDistinguish")
@Slf4j
public class PassRecordReportListener implements PlatFormEventListener {

    @Override
    public JsonResult event(Map resultMap) {
        //{"data":{"reportMessage":"{\"r2\":\"00\",\"r3\":\"01\",\"r4\":\"00 98 \",\"r1\":\"02\"}",
        // "product_code":"00000a05","serial_num":"00000a0518110227","account":"1563700000001964",
        // "cmd_id":"4190","cmd_name":"Report"},"modules":["apcos-cqxfydjc"]}
        String upDataStr = JSON.toJSONString(resultMap);
        if(resultMap == null){return JsonResult.ok(PassRecordReportListener.class);}
        if(!resultMap.containsKey("data") || !resultMap.containsKey("modules")){
            return JsonResult.ok(PassRecordReportListener.class);
        }
        JSONObject upDataJson = JSONObject.parseObject(upDataStr);
        String modules = upDataJson.get("modules").toString();
        // 只处理自己模块的上报信息
        if(modules.contains(Constant.MODULE_KEY)){
            log.info("智慧社区(泉州)门禁上报: " + upDataStr);

        }
        return JsonResult.error(upDataStr);
    }

}
